<?php
require_once 'pworks/mvc/IResult.iface.php';
require_once "xpface/util/data/DataSourceFactory.class.php";

class XPFaceResult implements IResult
{
    public function show(IAction &$action, ResultConfig $config)
    {
        //xpface config
        $xpFaceConfigLoader = XPFaceConfigLoader::getInstance();
        $xpFaceConfig = $xpFaceConfigLoader->getXPFaceConfig();
        //var_dump($xpFaceConfig);
        
        //page config
        $pageConfig = $xpFaceConfigLoader->getPageConfig();
        //var_dump($pageConfig);
        
        $_config = $pageConfig[$action->page_id];
        
        XPFace::setAction($action);
        //render
        $_data = $action->getData();
        //var_dump($_data);
        foreach ($data = $_data["binds"] as $key => $source) {
            $$key = DataSourceFactory::getData($source);
        }
        
        
        $_pagePermissions = $_data["__permission__"];
        $_pageId = $action->page_id;
        //var_dump($title);
        include($xpFaceConfig["parsed_tpl_path"]->value."/".$_config->template.".php");
        
        //var_dump($action);
        
        /*
        $page = PageLoader::load($action->page_id);
        $page->data = $action->getData();
		$page->messages = array_merge((array) $action->getErrors(), (array) $action->getWarnings(), (array) $action->getInfos());
        echo $page->render();
        */
    }
}
